HTTP 301
   HOME

TheInfoList



OR:

The HTTP response status code 301 Moved Permanently is used for permanent redirecting, meaning that links or records returning this response should be updated. The new URL should be provided in the Location field, included with the response. The 301 redirect is considered a best practice for upgrading users from HTTP to HTTPS. RFC 2616Fielding, ''et al'' (1999-06). "10.3.2 301 Moved Permanently". RFC 2616, p 61. IETF, June 1999. Retrieved from https://tools.ietf.org/html/rfc2616#section-10.3.2. states that: * If a client has link-editing capabilities, it should update all references to the Request URL. * The response is cacheable unless indicated otherwise. * Unless the request method was HEAD, the entity should contain a small hypertext note with a hyperlink to the new URL(s). * If the 301 status code is received in response to a request of any type other than GET or HEAD, the client must ask the user before redirecting.


Examples

Client request: GET /index.php HTTP/1.1 Host: www.example.org Server response: HTTP/1.1 301 Moved Permanently Location: https://www.example.org/index.asp


Using an .htaccess file

To fix problems with non-existing files or directories using a distributed .htaccess file: Redirect 301 /calendar.html /calendar/ Redirect 301 /not_found.html / Here is an example using a .htaccess file to redirect a non-secure URL to a secure address without the leading "www": RewriteEngine On RewriteCond % off RewriteCond % ^www\.(.*)$ CRewriteRule ^(.*)$ http://%1/$1 =301,L RewriteCond % on RewriteCond % ^www\.(.*)$ CRewriteRule ^(.*)$ https://%1/$1 =301,L RewriteEngine On RewriteCond % 80 RewriteRule ^(.*)$ https://example.com/$1 ,L 100% Completed


Static HTML

A custom directory redirect, using an index.html file:

Home


Using programming languages

Here is an example using
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offici ...
CGI.pm CGI.pm is a large and once widely used Perl module for programming Common Gateway Interface (CGI) web applications, providing a consistent API for receiving and processing user input. There are also functions for producing HTML or XHTML output ...
: print redirect("https://example.com/newpage.html"); Here is an example using a
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group. ...
redirect: Here is one way to redirect using Express.js: app.all("/old/url", (req, res) => );


Caching server

Equivalently simple for an
nginx Nginx (pronounced "engine x" ) is a web server that can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache. The software was created by Igor Sysoev and publicly released in 2004. Nginx is free and open-source software ...
configuration: location /old/urlblocked/ On


Search engines

Both
Bing Bing most often refers to: * Bing Crosby (1903–1977), American singer * Microsoft Bing, a web search engine Bing may also refer to: Food and drink * Bing (bread), a Chinese flatbread * Bing (soft drink), a UK brand * Bing cherry, a varie ...
and
Google Google LLC () is an American multinational technology company focusing on search engine technology, online advertising, cloud computing, computer software, quantum computing, e-commerce, artificial intelligence, and consumer electronics. ...
recommend using a 301 redirect to change the URL of a page as it is shown in search engine results, providing that URL will permanently change and is not due to be changed again any time soon.Site Move Tool - Bing Webmaster Help & How-to - https://www.bing.com/webmaster/help/how-to-use-the-site-move-tool-bb8f5112301 redirects - Google Webmaster Tools Help - https://support.google.com/webmasters/bin/answer.py?hl=en&answer=93633


See also

*
Hypertext Transfer Protocol The Hypertext Transfer Protocol (HTTP) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, ...
*
List of HTTP status codes This is a list of Hypertext Transfer Protocol (HTTP) response status codes. Status codes are issued by a server in response to a client's request made to the server. It includes codes from IETF Request for Comments (RFCs), other specifications, ...
*
URL redirection URL redirection, also called URL forwarding, is a World Wide Web technique for making a web page available under more than one URL address. When a web browser attempts to open a URL that has been redirected, a page with a different URL is opened ...


References

{{Reflist


Bibliography

301 HTTPS Hypertext Transfer Protocol status codes